//
//  LGInspectChartCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/30.
//

#import "LGInspectChartCell.h"

#define baseWidth     (Screen_W-viewPix(56))
#define dateWidth     (88/343.0)*baseWidth
#define itemWidth     (95/343.0)*baseWidth

@interface LGInspectChartCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIView *topLine;
/**   */
@property (nonatomic , strong)UIView *lineView1;
/**   */
@property (nonatomic , strong)UIView *lineView2;
/**   */
@property (nonatomic , strong)UIView *lineView3;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**   */
@property (nonatomic , strong)UILabel *resultLabel;
/**   */
@property (nonatomic , strong)UILabel *arrowLabel;
/**   */
@property (nonatomic , strong)UILabel *unitLabel;
/**   */
@property (nonatomic , strong)UILabel *rangeLabel;

@end

@implementation LGInspectChartCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.dateLabel.text = LGNSString(dataDic[@"datestr"]);
    self.resultLabel.text = LGNSString(dataDic[@"result"]);
    self.unitLabel.text = LGNSString(dataDic[@"unit"]);
    self.rangeLabel.text = LGNSString(dataDic[@"range"]);
    self.arrowLabel.text = LGNSString(dataDic[@"arrow"]);
    CGFloat width = [self.resultLabel.text textWidthWithFont:LGFont(14) maxHeight:MAXFLOAT];
    [self.arrowLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.resultLabel.mas_centerX).offset(width/2.0+3);
    }];
    NSString *colorString = [LGNSString(dataDic[@"status"]) isEqualToString:@"up"]?@"#DB453A":@"#429BFF";
    self.arrowLabel.textColor = [UIColor colorWithString:colorString];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.contentView.clipsToBounds = YES;
    self.contentView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.topLine];
    [self.baseView addSubview:self.dateLabel];
    [self.baseView addSubview:self.resultLabel];
    [self.baseView addSubview:self.arrowLabel];
    [self.baseView addSubview:self.unitLabel];
    [self.baseView addSubview:self.rangeLabel];
    [self.baseView addSubview:self.lineView1];
    [self.baseView addSubview:self.lineView2];
    [self.baseView addSubview:self.lineView3];
 
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(-viewPix(5));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView).offset(viewPix(5));
    }];
    [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(5));
        make.left.right.equalTo(self.baseView);
        make.height.equalTo(@(0.5));
    }];
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.equalTo(self.baseView);
        make.width.equalTo(@(dateWidth));
        make.height.equalTo(@(viewPix(40)));
    }];
    [self.resultLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.equalTo(self.dateLabel);
        make.left.equalTo(self.dateLabel.mas_right);
        make.width.equalTo(@(itemWidth));
    }];
    [self.arrowLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.resultLabel.mas_centerX);
        make.centerY.equalTo(self.resultLabel);
    }];
    [self.unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.equalTo(self.dateLabel);
        make.left.equalTo(self.resultLabel.mas_right);
        make.width.equalTo(@(itemWidth));
    }];
    [self.rangeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.equalTo(self.dateLabel);
        make.left.equalTo(self.unitLabel.mas_right);
        make.right.equalTo(self.baseView);
    }];
    [self.lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.dateLabel.mas_right);
        make.width.equalTo(@(0.5));
    }];
    [self.lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.resultLabel.mas_right);
        make.width.equalTo(@(0.5));
    }];
    [self.lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.unitLabel.mas_right);
        make.width.equalTo(@(0.5));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:10];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIView *)topLine{
    if(!_topLine){
        _topLine = [[UIView alloc] init];
        _topLine.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    }
    return _topLine;
}

-(UIView *)lineView1{
    if(!_lineView1){
        _lineView1 = [[UIView alloc] init];
        _lineView1.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    }
    return _lineView1;
}

-(UIView *)lineView2{
    if(!_lineView2){
        _lineView2 = [[UIView alloc] init];
        _lineView2.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    }
    return _lineView2;
}

-(UIView *)lineView3{
    if(!_lineView3){
        _lineView3 = [[UIView alloc] init];
        _lineView3.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    }
    return _lineView3;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"日期" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _dateLabel;
}

-(UILabel *)resultLabel{
    if(!_resultLabel){
        _resultLabel = [UILabel lableWithText:@"结果" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _resultLabel;
}

-(UILabel *)arrowLabel{
    if(!_arrowLabel){
        _arrowLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _arrowLabel;
}

-(UILabel *)unitLabel{
    if(!_unitLabel){
        _unitLabel = [UILabel lableWithText:@"单位" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _unitLabel;
}


-(UILabel *)rangeLabel{
    if(!_rangeLabel){
        _rangeLabel = [UILabel lableWithText:@"参考值" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:2];
    }
    return _rangeLabel;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
